<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript">
var detailValidator;
var assignValidator;

function selectExecutePerson() {
	$.openDialog("#dialog",
			{height:350,
			width:300,
			minHeight:350,
			minWidth:300,
			loadPage:ctx + "/biz/system/user/tree.jsp",
			title:"选择勘察人员"},
			function(data) {
				$("#taskExecPerson").data("id",data.data("id"));
				$("#taskExecPerson").val(data.data("name"));
			});
}

function selectProject() {
	$.openDialog("#dialog",
			{height:550,
			width:800,
			minHeight:450,
			minWidth:600,
			loadPage:ctx + "/biz/project/query.do",
			title:"选择项目"},
			function(data) {
				$("#taskProject").data("id",data.id);
				$("#taskProject").val(data.name);
			});
}

function selectPlanPoint() {
	$.openPointSelect("#dialog",
			{
				loadPage:ctx + "/biz/task/map_select.jsp",
				title:"点击地图选择坐标"
			},
			function(data) {
				$("#taskPlanLongitude").val(data.longitude);
				$("#taskPlanLatitude").val(data.latitude);
				$("#planLocationProvice").val(data.locationProvice);
				$("#planLocationCity").val(data.locationCity);
				$("#planLocationCounty").val(data.locationCounty);
				$("#planLocationStreet").val(data.locationStreet);
				$("#planLocationNumber").val(data.locationNumber);
				$("#planLocationAddress").val(data.locationAddress);
			}
	);
}

// function doDelete() {
// 	if (!confirm('是否删除？\n请确认是否继续操作 ！')) {
// 		return;
// 	}
	
// 	block("#supervForm");
// 	var id = $("#taskId").val();
// 	$.ajax({
// 		type: "POST",
// 		url: "delete.json",
// 		data: {"id": id},
// 		dataType: "json",
// 		success: function(data){
// 			unblock("#supervForm");
// 			if(!data.succeed){
// 				$.alert("删除失败，原因为：\n" + data.message);
// 				return;
// 			}
// 			$.info("删除成功！");
// 			goBack1();
// 		},
// 		error: function(message){
// 			unblock("#supervForm");
// 			$.alert("删除失败：" + message);
// 		}
// 	});
// }

function getSupervData(){
	var data = {
			id: $("#supervId").val(),
			taskId: $("#taskId").val(),
			constructionUnit: $("#constructionUnit").val(),
			constructionCase: $("#constructionCase").val(),
			constructionQuality: $("#constructionQuality").val(),
			constructionSafetyCulture: $("#constructionSafetyCulture").val(),
			otherSituations: $("#otherSituations").val(),
			rectificationMeasures: $("#rectificationMeasures").val(),
			recordDate: $("#recordDate").val(),
			taskContentOfTask: $("#taskContentOfTask").val(),
			taskDescriptionOfTask: $("#taskDescriptionOfTask").val()			
		};
	return data;
}

function doSave() {
	if (!detailValidator.form()) {
		return;
	}
	
	block("#supervForm");
	$.ajax({
		type: "POST",
		url: "superv/save.json",
		data: getSupervData(),
		dataType: "json",
		success: saveSupervSucceedCallback,
		error:function(message){
			unblock("#supervForm");
			$.alert("出错了，错误信息为：\n"+message);
		}
	});
}

function saveSupervSucceedCallback(data) {
	unblock("#supervForm");
	if (!data.succeed) {
		$.notice("保存失败，原因为：\n"+data.message);
		return;
	}
	$.info("保存成功！");
	loadSupervSucceedCallback(data);
}
function loadSupervItem(){
	var id = $("#supervId").val();
	if(id == undefined || id == ""){
		return;
	}
	
	block("#supervForm");
	$.ajax({
		type: "GET",
		cache: false,
		url: "superv/detail.json?id=" + id,
		dataType: "json",
		success: loadSupervSucceedCallback,
		error:function(message){
			unblock("#supervForm");
			$.alert(message);
		}  
	});	
}

function loadSupervSucceedCallback(data){
	unblock("#supervForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}
// 	var status = data.data.status;
// 	if(status == "in_process" || status == "completed" || status == ""){
// 		location.href = "detail.do?id=" + data.data.id;
// 	}	
	
	fillSupervItem(data.data);
	
	var supervId = $("#supervId").val();
	if(supervId == undefined || supervId == ""){
		$("#exportButton").hide();
	}else{
		$("#exportButton").show();
	}
}

function fillSupervItem(item){
	//$("#taskTitle").text(" - " + item.name);
	//$("#taskId").val(item.taskId);
	
	$("#supervId").val(item.id);
	$("#constructionUnit").val(item.constructionUnit);
	$("#constructionCase").val(item.constructionCase);
	$("#constructionQuality").val(item.constructionQuality);
	$("#constructionSafetyCulture").val(item.constructionSafetyCulture);
	$("#otherSituations").val(item.otherSituations);
	$("#rectificationMeasures").val(item.rectificationMeasures);
	$("#recordDate").val(item.recordDate);
// 	$("#recordDate").val((item.recordDate!=null)?item.recordDate.slice(0,10):item.recordDate);
	
	$("#taskContentOfTask").val(item.taskContentOfTask);
	$("#taskDescriptionOfTask").val(item.taskDescriptionOfTask);
	//重置基本信息页面
	$("#taskContent").val(item.taskContentOfTask);
	$("#taskDescription").val(item.taskDescriptionOfTask);
}

$(document).ready(function() {
	//$('#taskPlanStartDate').datepicker();
	//$('#recordDate').datepicker();
	$("textarea").tah({
		moreSpace:10
	});
	$().maxlength();
	
	loadSupervItem();
	
	detailValidator = $("#supervForm").validate({
		rules: {
			taskContentOfTask:{required:false, maxlength:1000},
			taskDescriptionOfTask:{required:false, maxlength:1000},
			constructionUnit:{required:true, maxlength:100 },
			constructionCase:{required:true, maxlength:1000 },
			constructionQuality:{required:true, maxlength:1000 },
			constructionSafetyCulture:{required:true, maxlength:1000 },
			otherSituations:{required:true, maxlength:1000 },
			rectificationMeasures:{required:true, maxlength:1000 }
			//,
			//recordDate:{required:true, dateISO:true}
		},
		messages:{
			taskContentOfTask:{required:"请输入任务描述", maxlength:"任务描述不能超过1000个字符"},
			taskDescriptionOfTask:{maxlength:"勘察内容不能超过1000个字符"},
			constructionUnit:{required:"请输入施工单位",maxlength:"施工单位不能超过1000个字符"},
			constructionCase:{required:"请输入施工动态",maxlength:"施工动态不能超过1000个字符"},
			constructionQuality:{required:"请输入施工质量",maxlength:"施工质量不能超过1000个字符"},
			constructionSafetyCulture:{required:"请输入安全文明施工",maxlength:"安全文明施工不能超过1000个字符"},
			otherSituations:{required:"请输入其他情况记录",maxlength:"其他情况记录不能超过1000个字符"},
			rectificationMeasures:{required:"请输入其他情况记录", maxlength:"其他情况记录不能超过1000个字符"}
			//,
			//recordDate:{required:"请输入填报时间", dateISO:"请输入有效日期，如2012-12-21"}
		}
	});

});
</script>
<div id="supervCarousel" class="carousel slide">
<form id="supervForm" class="form-horizontal">
<input type="hidden" id="supervId" name="supervId" />

<fieldset>
	<div class="control-group">
		<label for="taskContentOfTask"  class="control-label">任务描述：</label>
		<div class="controls">
		<textarea id="taskContentOfTask" name="taskContentOfTask"></textarea>
		</div>
	</div>
	<div class="control-group">
		<label for="taskDescriptionOfTask"  class="control-label">勘察内容：</label>
		<div class="controls">
		<textarea id="taskDescriptionOfTask" name="taskDescriptionOfTask"></textarea>
		</div>
	</div>
	<div class="control-group">
		<label for="constructionUnit"  class="control-label">施工单位：</label>
		<div class="controls">
		<input type="text" id="constructionUnit" name="constructionUnit" maxlength="255" /> <span class="cms_color_required">*</span>
		</div>
	</div>	
	<div class="control-group">
		<label for="constructionCase"  class="control-label">施工动态：</label>
		<div class="controls">
		<textarea id="constructionCase" name="constructionCase" maxlength="2048"> </textarea> <span class="cms_color_required">*</span>
		</div> 
	</div>
	
	<div class="control-group">
		<label for="constructionQuality"  class="control-label">施工质量：</label>
		<div class="controls">
		<textarea id="constructionQuality" name="constructionQuality" maxlength="512"> </textarea> <span class="cms_color_required">*</span>
		</div>
	</div>	
	<div class="control-group">
		<label for="constructionSafetyCulture"  class="control-label">安全文明施工：</label>
		<div class="controls">
		<textarea id="constructionSafetyCulture" name="constructionSafetyCulture" maxlength="512" > </textarea> <span class="cms_color_required">*</span>
		</div>
	</div>	
	<div class="control-group">
		<label for="otherSituations"  class="control-label">其他情况记录：</label>
		<div class="controls">
		<textarea id="otherSituations" name="otherSituations" maxlength="2048" > </textarea> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="rectificationMeasures"  class="control-label">整改措施及处理情况：</label>
		<div class="controls">
		<textarea id="rectificationMeasures" name="rectificationMeasures" maxlength="2048" > </textarea> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="recordDate"  class="control-label">填报时间：</label>
		<div class="controls">
		<input type="text" id="recordDate" name="recordDate" readonly="readonly" />
		</div>
	</div>
	<div class="form-actions">
		<a id="saveBtn" href="javascript:void(0);" class="btn btn-primary" onclick="doSave()"><i class="icon-ok"></i>保存</a>
<!-- 		<a id="deleteBtn" href="javascript:void(0);" class="btn btn-danger" style="display: none;" onclick="doDelete()"><i class="icon-remove"></i>删除</a> -->
	</div>
</fieldset>
</form>
</div>